﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Linq.Mapping;
using System.Text.RegularExpressions;
using Entities;
using BLL;

namespace QLTB_CTK34
{
    public delegate void XuLiData(List<object> ds);
    public partial class UCCompare : UserControl
    {
        public UCCompare()
        {
            InitializeComponent();
           
        }
        public Type type;
        public DataGridView dgv;
        public IEnumerable<object> ds;
        public List<object> newds;
        public XuLiData xldt;
        public void InitColumnName(Type _type, DataGridView _dgv, IEnumerable<object> _ds)
        {
            ThuVien.TRY_CATCH(() =>
                {
                    type = _type;
                    dgv = _dgv;
                    ds = _ds;
                    var list_column = GetDisplayColumnName.ds.FindAll(x => x.TableName == type.Name);
                    foreach (var item in list_column)
                    {
                        cbbColumnNameCompare.Items.Add(item.DisPlayColumnName);
                    }
                },1);
        }
        private void txtValueCompare_TextChanged(object sender, EventArgs e)
        {

             newds = new List<object>();

                
                foreach (var x in ds)
                {
                    DisplayColumnName column_infor = GetDisplayColumnName.ds.Find(x1 => x1.DisPlayColumnName == cbbColumnNameCompare.Text);
                    object myvalue = type.GetProperty(column_infor.ColumnName).GetValue(x, null);
                    bool kq = column_infor.Compare(txtValueCompare.Text, myvalue, cbbCompareType.Text);
                    if (kq)
                        newds.Add(x);
                }
                xldt(newds);

           
        }

        private void UCCompare_Click(object sender, EventArgs e)
        {
          //  this.BackColor = Color.Red;
        }
    }
}
